package com.gitee.wsl.func.procedure.sample

import com.gitee.wsl.func.predicate.Predicate
import com.gitee.wsl.func.procedure.Procedure

/**
 * Applies a predicate to an object to determine if it should be added to a target collection.
 */
class RejectProcedure<T>(
    private val predicate: Predicate<in T>,
    val collection: MutableCollection<T>
) : Procedure<T> {
    override fun value(each: T) {
        if (!this.predicate.accept(each)) {
            this.collection.add(each)
        }
    }
}
